<?php
/**
 * BQue Description
 * @package core.lib
 * @name Controller
 * @filesource Controller.php
 * @author Meta Sanjaya
 */

class Controller extends Registry
{
    private $variable;
    private $template;

    /**
     * @access public
     * @method __construct
     * @param void
     * @return void
     */
    public function __construct()
    {
        $this->variable = array();
        $this->template = $this->config->get('default_template');
    }

    /**
     * @access protected
     * @method addVar
     * @param String $name
     * @param Mixed $value
     * @return void
     */
    protected function addVar($name, $value)
    {
        $this->variable[$name] = $value;
    }

    /**
     * @access protected
     * @method setView
     * @param String $view
     * @return void
     */
    protected function setView($view)
    {
        $this->view->setView($view);
    }

    /**
     * @access protected
     * @method renderView
     * @param Boolean $return
     * @return Mixed
     */
    protected function renderView($return=false)
    {
        $return = $this->view->renderOutput($this->variable, $return);
        $this->variable = array();
        return $return;
    }

    /**
     * @access protected
     * @method loadModel
     * @param String $model
     * @return void
     */
    protected function loadModel($model)
    {
        if(is_null($model))
        {
            $model = $this->app->getDirectory() . 'model/' . $this->app->getController();
        }
        
        $this->load->model($model);
    }

    /**
     * @access protected
     * @method loadLanguage
     * @param String $language
     * @return void 
     */
    protected function loadLanguage($language)
    {
        if(is_null($language))
        {
            $language = $this->app->getDirectory() . 'language/' . $this->app->getController();
        }

        $this->load->language($language);
    }

    /**
     * @access protected
     * @method __set
     * @override
     * @param String $name
     * @param Class $value
     * @return void
     */
    protected function __set($name, $value)
    {
        $this->$name = $value;
    }

    /**
     * @access protected
     * @method __get
     * @override
     * @param String $name
     * @return Class 
     */
    protected function __get($name)
    {
        return $this->$name;
    }
}
?>
